package com.ruoyi.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.entity.LoginVo;
import com.ruoyi.entity.UserDTO;
import com.ruoyi.entity.UserOrderDto;
import com.ruoyi.service.UserOrderService;
import com.ruoyi.utils.JwtTokenUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@Tag(name = "用户订单及优惠券", description = "提供用户订单、优惠券相关操作接口")
@RequestMapping("/api/userOrders")
public class UserOrderController extends BaseController {
    @Autowired
    private UserOrderService userOrderService;

    @Autowired
    private JwtTokenUtils jwtTokenUtils;

    @GetMapping("/getAccountInfo")
    @Operation(summary = "查询用户订单及优惠券信息", description = "支持按订单状态筛选，使用若依框架分页")
    public AjaxResult getUserInfo(@RequestParam Long userId) {
        try {
            UserDTO userDTO = userOrderService.getUserOrderList(userId);
            if (userDTO == null) {
                return AjaxResult.success("用户不存在", null);
            }
            return AjaxResult.success("查询成功", userDTO);
        } catch (IllegalArgumentException e) {
            return AjaxResult.error(e.getMessage());
        } catch (Exception e) {
            return AjaxResult.error("查询失败：" + e.getMessage());
        }
    }
}
